package ru.urfc.portal.rest;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import ru.urfc.portal.managers.NotificationManager;
import ru.urfc.portal.model.NotificationSettings;
import ru.urfc.portal.services.NotificationTimer;
import ru.urfc.portal.ui.client.Constants;

@Stateless
@Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
@Path(Constants.GLOBAL_NOTIFICATION_SETTINGS) 
public class GlobalNotificationSettingsService extends BaseService {
	
	@EJB NotificationManager notificationManager;
	@EJB NotificationTimer notificationTimer;
	
	@GET
	public NotificationSettings getGlobal() {
		return notificationManager.getGlobal();
	}
	
	@PUT
	public NotificationSettings updateGlobal(NotificationSettings settings) {
		return notificationManager.updateGlobalSettings(settings);
	}
	
	@PUT
	@Path(NOTIFY_ALL)
	public void notifyByEmail() {
		notificationTimer.scheduledTimeout(null);
		Response.ok().build();
	}
	
}

